package newKe;

import java.util.Scanner;

public class HJ65 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int maxlen = 0;
        int left = 0;
        String s1 = in.nextLine();
        String s2 = in.nextLine();

        int len1 = s1.length(),len2 = s2.length();
        if(len1<len2){
            for(int L = 1;L<s1.length();L++){
                for(int i=0;i<s1.length();i++){
                    //j-i+1=L
                    int j = L+i-1;
                    if(j>=s1.length()) break;

                    String sun = s1.substring(i,i+L);
                    if(s2.contains(sun)){
                        if(L>maxlen){
                            maxlen = L;
                            left = i;
                        }
                    }

                }
            }
            System.out.println(s1.substring(left,left+maxlen));
        }else{
            for(int L = 1;L<s2.length();L++){
                for(int i=0;i<s2.length();i++){
                    //j-i+1=L
                    int j = L+i-1;
                    if(j>=s2.length()) break;

                    String sun = s2.substring(i,i+L);
                    if(s1.contains(sun)){
                        if(L>maxlen){
                            maxlen = L;
                            left = i;
                        }
                    }

                }
            }
            System.out.println(s2.substring(left,left+maxlen));
        }


    }
}
